/*
 * Copyright (c) Huawei Device Co., Ltd. 2023. All rights reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include "channel_impl.h"
#include "channel.h"
#include "reader_impl.h"
#include "service_impl.h"
#include "secure_element_agent.h"
#include "loghelper.h"
#include "ipc_object_stub.h"
#include "session.h"
#include "se_service.h"
#include "service_manager.h"
#include "reader.h"
#include "session_impl.h"

#include <gtest/gtest.h>
#include <memory>

namespace OHOS {
namespace SE {
namespace TEST {
using namespace testing::ext;
using namespace OHOS::SE::OMAPI;
static const std::string CHANNEL_NUMBER = "A000000151000000";
static const std::string GET_CPLC = "80CA9F7F00";
static bool g_isSeSupported = false;

class ChannelImplTest : public testing::Test {
public:
    static void SetUpTestCase() {};
    static void TearDownTestCase() {};
    void SetUp();
    void TearDown();
public:
    std::shared_ptr<SEService> seService_;
    std::shared_ptr<Reader> reader_;
    std::shared_ptr<Session> session_;
    std::shared_ptr<Channel> channel_;
};

void ChannelImplTest::SetUp()
{
    InfoLog("ChannelImplTest::SetUp begin!");
    seService_ = std::make_shared<SEService>();
    bool initStatus = false;
    seService_->InitSEService(initStatus, nullptr);
    sleep(1);
    EXPECT_TRUE(initStatus);
    vector<std::shared_ptr<Reader>> readerLists;
    seService_->GetReaders(readerLists);
    g_isSeSupported = readerLists.empty();
    if (g_isSeSupported) {
        ErrorLog("se not support!");
        return;
    }
    for (auto reader : readerLists) {
        std::string readerName {};
        reader->GetName(readerName);
        if (readerName.compare("eSE") == 0) {
            reader_ = reader;
            break;
        }
    }
    EXPECT_TRUE(reader_);
    if (reader_ != nullptr) {
        reader_->OpenSession(session_);
    }
    EXPECT_TRUE(session_);
    if (session_ != nullptr) {
        std::string response = "";
        session_->OpenLogicalChannel(CHANNEL_NUMBER, 0, channel_, response);
    }

    EXPECT_TRUE(channel_);
    InfoLog("ChannelImplTest::SetUp done!");
}

void ChannelImplTest::TearDown()
{
    InfoLog("LogicalChannelTest::TearDown begin!");
    if (g_isSeSupported) {
        ErrorLog("se not support!");
        return;
    }
    if (channel_) {
        channel_->Close();
        channel_ = nullptr;
    }
    if (session_) {
        session_->Close();
        session_ = nullptr;
    }
    if (reader_) {
        reader_->CloseSessions();
        reader_ = nullptr;
    }
    if (seService_) {
        seService_->Shutdown();
        seService_ = nullptr;
    }
    InfoLog("LogicalChannelTest::TearDown done!");
}

/**
 * @tc.name: Close_Test001
 * @tc.desc: Test Session Close.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, Close_Test001, TestSize.Level1)
{
    std::weak_ptr<SecureElementAgent> agent;
    bool isBasic = false;
    uint8_t channelNumber = 0;
    std::string selectResponse = "";
    std::shared_ptr<ChannelImpl> channelImpl = std::make_shared<ChannelImpl>(agent, isBasic, channelNumber, selectResponse);
    ErrorCode errorCode = channelImpl->Close();
    EXPECT_TRUE(errorCode == ErrorCode::SE_ILLEGAL_STATE_ERROR);
}

/**
 * @tc.name: Close_Test002
 * @tc.desc: Test Session Close.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, Close_Test002, TestSize.Level1)
{
    std::shared_ptr<SecureElementAgent> agent = std::make_shared<SecureElementAgent>("");
    bool isBasic = false;
    uint8_t channelNumber = 0;
    std::string selectResponse = "";
    std::shared_ptr<ChannelImpl> channelImpl = std::make_shared<ChannelImpl>(agent, isBasic, channelNumber, selectResponse);
    channelImpl->Close();
    ErrorCode errorCode = channelImpl->Close();
    EXPECT_TRUE(errorCode == ErrorCode::SE_SUCCESS);
}

/**
 * @tc.name: GetSelectResponse_Test001
 * @tc.desc: Test Session GetSelectResponse.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, GetSelectResponse_Test001, TestSize.Level1)
{
    std::weak_ptr<SecureElementAgent> agent;
    bool isBasic = false;
    uint8_t channelNumber = 0;
    std::string selectResponse = "";
    std::shared_ptr<ChannelImpl> channelImpl = std::make_shared<ChannelImpl>(agent, isBasic, channelNumber, selectResponse);
    ErrorCode errorCode = channelImpl->GetSelectResponse(selectResponse);
    EXPECT_TRUE(errorCode == ErrorCode::SE_ILLEGAL_STATE_ERROR);
}

/**
 * @tc.name: GetSelectResponse_Test002
 * @tc.desc: Test Session GetSelectResponse.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, GetSelectResponse_Test002, TestSize.Level1)
{
    std::shared_ptr<SecureElementAgent> agent = std::make_shared<SecureElementAgent>("");
    bool isBasic = false;
    uint8_t channelNumber = 0;
    std::string selectResponse = "";
    std::shared_ptr<ChannelImpl> channelImpl = std::make_shared<ChannelImpl>(agent, isBasic, channelNumber, selectResponse);
    channelImpl->Close();
    ErrorCode errorCode = channelImpl->GetSelectResponse(selectResponse);
    EXPECT_TRUE(errorCode == ErrorCode::SE_ILLEGAL_STATE_ERROR);
}

/**
 * @tc.name: Transmit_Test001
 * @tc.desc: Test Session Transmit.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, Transmit_Test001, TestSize.Level1)
{
    std::weak_ptr<SecureElementAgent> agent;
    bool isBasic = false;
    uint8_t channelNumber = 0;
    std::string command = "";
    std::string response = "";
    std::string selectResponse = "";
    std::shared_ptr<ChannelImpl> channelImpl = std::make_shared<ChannelImpl>(agent, isBasic, channelNumber, selectResponse);
    ErrorCode errorCode = channelImpl->Transmit(command, response);
    EXPECT_TRUE(errorCode == ErrorCode::SE_ILLEGAL_STATE_ERROR);
}

/**
 * @tc.name: Transmit_Test002
 * @tc.desc: Test Session Transmit.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, Transmit_Test002, TestSize.Level1)
{
    std::shared_ptr<SecureElementAgent> agent = std::make_shared<SecureElementAgent>("");
    bool isBasic = false;
    uint8_t channelNumber = 0;
    std::string command = "";
    std::string response = "";
    std::string selectResponse = "";
    std::shared_ptr<ChannelImpl> channelImpl = std::make_shared<ChannelImpl>(agent, isBasic, channelNumber, selectResponse);
    channelImpl->Close();
    ErrorCode errorCode = channelImpl->Transmit(command, response);
    EXPECT_TRUE(errorCode == ErrorCode::SE_ILLEGAL_STATE_ERROR);
}

/**
 * @tc.name: Transmit_Test003
 * @tc.desc: Test Session Transmit.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, Transmit_Test003, TestSize.Level1)
{
    std::shared_ptr<SecureElementAgent> agent = std::make_shared<SecureElementAgent>("eSE");
    agent->Initialize();
    agent->OnStateChange(true);
    bool isBasic = false;
    uint8_t channelNumber = 0;
    std::string command = "00000000";
    std::string response = "";
    std::string selectResponse = "";
    std::shared_ptr<ChannelImpl> channelImpl = std::make_shared<ChannelImpl>(agent, isBasic, channelNumber, selectResponse);
    channelImpl->SetChannelState(false);
    ErrorCode errorCode = channelImpl->Transmit(command, response);
    EXPECT_TRUE(errorCode == ErrorCode::SE_SUCCESS);
}

/**
 * @tc.name: Transmit_Test004
 * @tc.desc: Test Session Transmit.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, Transmit_Test004, TestSize.Level1)
{
    std::shared_ptr<SecureElementAgent> agent = std::make_shared<SecureElementAgent>("eSE");
    agent->Initialize();
    agent->OnStateChange(true);
    bool isBasic = false;
    uint8_t channelNumber = 0;
    std::string command = "80000000";
    std::string response = "";
    std::string selectResponse = "";
    std::shared_ptr<ChannelImpl> channelImpl = std::make_shared<ChannelImpl>(agent, isBasic, channelNumber, selectResponse);
    channelImpl->SetChannelState(false);
    ErrorCode errorCode = channelImpl->Transmit(command, response);
    EXPECT_TRUE(errorCode == ErrorCode::SE_SUCCESS);
}

/**
 * @tc.name: Transmit_Test005
 * @tc.desc: Test Session Transmit.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, Transmit_Test005, TestSize.Level1)
{
    std::shared_ptr<SecureElementAgent> agent = std::make_shared<SecureElementAgent>("eSE");
    agent->Initialize();
    agent->OnStateChange(true);
    bool isBasic = false;
    uint8_t channelNumber = 19;
    std::string command = "80000000";
    std::string response = "";
    std::string selectResponse = "";
    std::shared_ptr<ChannelImpl> channelImpl = std::make_shared<ChannelImpl>(agent, isBasic, channelNumber, selectResponse);
    channelImpl->SetChannelState(false);
    ErrorCode errorCode = channelImpl->Transmit(command, response);
    EXPECT_TRUE(errorCode == ErrorCode::SE_SUCCESS);
}

/**
 * @tc.name: IsSecureElementPresent_Test001
 * @tc.desc: Test Session IsSecureElementPresent.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, IsSecureElementPresent_Test001, TestSize.Level1)
{
    std::weak_ptr<SecureElementAgent> agent;
    bool isPresent = false;
    std::shared_ptr<ReaderImpl> readerImpl = std::make_shared<ReaderImpl>(agent);
    ErrorCode errorCode = readerImpl->IsSecureElementPresent(isPresent);
    EXPECT_TRUE(errorCode == ErrorCode::SE_ILLEGAL_STATE_ERROR);
}

/**
 * @tc.name: OpenSession_Test001
 * @tc.desc: Test Session OpenSession.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, OpenSession_Test001, TestSize.Level1)
{
    std::weak_ptr<SecureElementAgent> agent;
    sptr<OMAPI::ISecureElementSession> session = nullptr;
    std::shared_ptr<ReaderImpl> readerImpl = std::make_shared<ReaderImpl>(agent);
    ErrorCode errorCode = readerImpl->OpenSession(session);
    EXPECT_TRUE(errorCode == ErrorCode::SE_ILLEGAL_STATE_ERROR);
}

/**
 * @tc.name: CloseSessions_Test001
 * @tc.desc: Test Session CloseSessions.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, CloseSessions_Test001, TestSize.Level1)
{
    std::weak_ptr<SecureElementAgent> agent;
    std::shared_ptr<ReaderImpl> readerImpl = std::make_shared<ReaderImpl>(agent);
    ErrorCode errorCode = readerImpl->CloseSessions();
    EXPECT_TRUE(errorCode == ErrorCode::SE_ILLEGAL_STATE_ERROR);
}

/**
 * @tc.name: Reset_Test001
 * @tc.desc: Test Session Reset.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, Reset_Test001, TestSize.Level1)
{
    std::weak_ptr<SecureElementAgent> agent;
    bool resetStatus = false;
    std::shared_ptr<ReaderImpl> readerImpl = std::make_shared<ReaderImpl>(agent);
    ErrorCode errorCode = readerImpl->Reset(resetStatus);
    EXPECT_TRUE(errorCode == ErrorCode::SE_ILLEGAL_STATE_ERROR);
}

/**
 * @tc.name: GetAtr_Test001
 * @tc.desc: Test Session GetAtr.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, GetAtr_Test001, TestSize.Level1)
{
    std::weak_ptr<SecureElementAgent> agent;
    std::shared_ptr<ReaderImpl> readerImpl = std::make_shared<ReaderImpl>(agent);
    std::string ret = readerImpl->GetAtr();
    EXPECT_TRUE(ret == std::string());
}

/**
 * @tc.name: OnStateChange_Test001
 * @tc.desc: Test Session OnStateChange.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, OnStateChange_Test001, TestSize.Level1)
{
    std::string name = "";
    bool connected = false;
    std::shared_ptr<SecureElementAgent> agent = std::make_shared<SecureElementAgent>(name);
    agent->OnStateChange(connected);
    EXPECT_TRUE(agent != nullptr);
}

/**
 * @tc.name: Initialize_Test001
 * @tc.desc: Test Session Initialize.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, Initialize_Test001, TestSize.Level1)
{
    std::string name = "";
    bool connected = true;
    std::shared_ptr<SecureElementAgent> agent = std::make_shared<SecureElementAgent>(name);
    agent->OnStateChange(connected);
    bool ret = agent->Initialize();
    EXPECT_TRUE(ret);
}

/**
 * @tc.name: Initialize_Test002
 * @tc.desc: Test Session Initialize.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, Initialize_Test002, TestSize.Level1)
{
    std::string name = "eSE";
    std::shared_ptr<SecureElementAgent> agent = std::make_shared<SecureElementAgent>(name);
    bool ret = agent->Initialize();
    EXPECT_TRUE(ret);
}

/**
 * @tc.name: IsSecureElementPresentA_Test001
 * @tc.desc: Test Session IsSecureElementPresent.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, IsSecureElementPresentA_Test001, TestSize.Level1)
{
    std::string name = "";
    std::shared_ptr<SecureElementAgent> agent = std::make_shared<SecureElementAgent>(name);
    bool ret = agent->IsSecureElementPresent();
    EXPECT_TRUE(!ret);
}

/**
 * @tc.name: IsSecureElementPresentA_Test002
 * @tc.desc: Test Session IsSecureElementPresent.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, IsSecureElementPresentA_Test002, TestSize.Level1)
{
    std::string name = "eSE";
    bool connected = true;
    std::shared_ptr<SecureElementAgent> agent = std::make_shared<SecureElementAgent>(name);
    agent->OnStateChange(connected);
    bool ret = agent->IsSecureElementPresent();
    EXPECT_TRUE(!ret);
}

/**
 * @tc.name: IsSecureElementPresentA_Test003
 * @tc.desc: Test Session IsSecureElementPresent.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, IsSecureElementPresentA_Test003, TestSize.Level1)
{
    std::string name = "eSE";
    bool connected = true;
    std::shared_ptr<SecureElementAgent> agent = std::make_shared<SecureElementAgent>(name);
    agent->Initialize();
    agent->OnStateChange(connected);
    bool ret = agent->IsSecureElementPresent();
    EXPECT_TRUE(ret);
}

/**
 * @tc.name: IsSecureElementPresentA_Test004
 * @tc.desc: Test Session IsSecureElementPresent.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, IsSecureElementPresentA_Test004, TestSize.Level1)
{
    std::string name = "SIM";
    bool connected = true;
    std::shared_ptr<SecureElementAgent> agent = std::make_shared<SecureElementAgent>(name);
    agent->OnStateChange(connected);
    bool ret = agent->IsSecureElementPresent();
    EXPECT_TRUE(!ret);
}

/**
 * @tc.name: IsSecureElementPresentA_Test005
 * @tc.desc: Test Session IsSecureElementPresent.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, IsSecureElementPresentA_Test005, TestSize.Level1)
{
    std::string name = "SIM";
    bool connected = true;
    std::shared_ptr<SecureElementAgent> agent = std::make_shared<SecureElementAgent>(name);
    agent->Initialize();
    agent->OnStateChange(connected);
    bool ret = agent->IsSecureElementPresent();
    EXPECT_TRUE(!ret);
}

/**
 * @tc.name: IsSecureElementPresentA_Test006
 * @tc.desc: Test Session IsSecureElementPresent.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, IsSecureElementPresentA_Test006, TestSize.Level1)
{
    std::string name = "";
    bool connected = true;
    std::shared_ptr<SecureElementAgent> agent = std::make_shared<SecureElementAgent>(name);
    agent->OnStateChange(connected);
    bool ret = agent->IsSecureElementPresent();
    EXPECT_TRUE(!ret);
}

/**
 * @tc.name: GetAtrA_Test001
 * @tc.desc: Test Session GetAtr.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, GetAtrA_Test001, TestSize.Level1)
{
    std::string name = "";
    bool connected = false;
    std::shared_ptr<SecureElementAgent> agent = std::make_shared<SecureElementAgent>(name);
    agent->OnStateChange(connected);
    std::string ret = agent->GetAtr();
    EXPECT_TRUE(ret == "");
}

/**
 * @tc.name: GetAtrA_Test002
 * @tc.desc: Test Session GetAtr.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, GetAtrA_Test002, TestSize.Level1)
{
    std::string name = "eSE";
    bool connected = true;
    std::shared_ptr<SecureElementAgent> agent = std::make_shared<SecureElementAgent>(name);
    agent->OnStateChange(connected);
    std::string ret = agent->GetAtr();
    EXPECT_TRUE(ret == "");
}

/**
 * @tc.name: GetAtrA_Test003
 * @tc.desc: Test Session GetAtr.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, GetAtrA_Test003, TestSize.Level1)
{
    std::string name = "eSE";
    bool connected = true;
    std::shared_ptr<SecureElementAgent> agent = std::make_shared<SecureElementAgent>(name);
    agent->Initialize();
    agent->OnStateChange(connected);
    std::string ret = agent->GetAtr();
    EXPECT_TRUE(ret != "");
}

/**
 * @tc.name: GetAtrA_Test004
 * @tc.desc: Test Session GetAtr.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, GetAtrA_Test004, TestSize.Level1)
{
    std::string name = "SIM";
    bool connected = true;
    std::shared_ptr<SecureElementAgent> agent = std::make_shared<SecureElementAgent>(name);
    agent->OnStateChange(connected);
    std::string ret = agent->GetAtr();
    EXPECT_TRUE(ret == "");
}

/**
 * @tc.name: GetAtrA_Test005
 * @tc.desc: Test Session GetAtr.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, GetAtrA_Test005, TestSize.Level1)
{
    std::string name = "SIM";
    bool connected = true;
    std::shared_ptr<SecureElementAgent> agent = std::make_shared<SecureElementAgent>(name);
    agent->Initialize();
    agent->OnStateChange(connected);
    std::string ret = agent->GetAtr();
    EXPECT_TRUE(ret != "");
}

/**
 * @tc.name: TransmitA_Test001
 * @tc.desc: Test Session Transmit.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, TransmitA_Test001, TestSize.Level1)
{
    std::string name = "eSE";
    bool connected = true;
    std::string cmd = "80CA9F7F00";
    std::shared_ptr<SecureElementAgent> agent = std::make_shared<SecureElementAgent>(name);
    agent->Initialize();
    agent->OnStateChange(connected);
    std::string ret = agent->Transmit(cmd);
    EXPECT_TRUE(ret != std::string{});
}

/**
 * @tc.name: TransmitA_Test002
 * @tc.desc: Test Session Transmit.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, TransmitA_Test002, TestSize.Level1)
{
    std::string name = "eSE";
    bool connected = true;
    std::string cmd = "";
    std::shared_ptr<SecureElementAgent> agent = std::make_shared<SecureElementAgent>(name);
    agent->Initialize();
    agent->OnStateChange(connected);
    std::string ret = agent->Transmit(cmd);
    EXPECT_TRUE(ret != std::string{});
}

/**
 * @tc.name: TransmitA_Test003
 * @tc.desc: Test Session Transmit.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, TransmitA_Test003, TestSize.Level1)
{
    std::string name = "eSE";
    bool connected = true;
    std::string cmd = "80CA9F7F00";
    std::shared_ptr<SecureElementAgent> agent = std::make_shared<SecureElementAgent>(name);
    agent->Initialize();
    agent->OnStateChange(connected);
    std::string ret = agent->Transmit(cmd);
    EXPECT_TRUE(ret != std::string{});
}

/**
 * @tc.name: TransmitA_Test004
 * @tc.desc: Test Session Transmit.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, TransmitA_Test004, TestSize.Level1)
{
    std::string name = "SIM";
    bool connected = true;
    std::string cmd = "";
    std::shared_ptr<SecureElementAgent> agent = std::make_shared<SecureElementAgent>(name);
    agent->Initialize();
    agent->OnStateChange(connected);
    std::string ret = agent->Transmit(cmd);
    EXPECT_TRUE(ret != std::string{});
}

/**
 * @tc.name: TransmitA_Test005
 * @tc.desc: Test Session Transmit.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, TransmitA_Test005, TestSize.Level1)
{
    std::string name = "SIM";
    bool connected = true;
    std::string cmd = "80CA9F7F00";
    std::shared_ptr<SecureElementAgent> agent = std::make_shared<SecureElementAgent>(name);
    agent->Initialize();
    agent->OnStateChange(connected);
    std::string ret = agent->Transmit(cmd);
    EXPECT_TRUE(ret != std::string{});
}

/**
 * @tc.name: CloseChannelA_Test001
 * @tc.desc: Test Session CloseChannel.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, CloseChannelA_Test001, TestSize.Level1)
{
    std::string name = "eSE";
    bool connected = false;
    uint8_t channelNum = 0;
    bool isBasicChannel = false;
    std::string callingUniqueTag;
    std::shared_ptr<SecureElementAgent> agent = std::make_shared<SecureElementAgent>(name);
    agent->OnStateChange(connected);
    agent->CloseChannel(channelNum, isBasicChannel, callingUniqueTag);
    EXPECT_TRUE(agent != nullptr);
}

/**
 * @tc.name: CloseChannelA_Test002
 * @tc.desc: Test Session CloseChannel.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, CloseChannelA_Test002, TestSize.Level1)
{
    std::string name = "eSE";
    bool connected = true;
    uint8_t channelNum = 101;
    bool isBasicChannel = false;
    std::string callingUniqueTag;
    std::shared_ptr<SecureElementAgent> agent = std::make_shared<SecureElementAgent>(name);
    agent->OnStateChange(connected);
    agent->CloseChannel(channelNum, isBasicChannel, callingUniqueTag);
    EXPECT_TRUE(agent != nullptr);
}

/**
 * @tc.name: CloseChannelA_Test003
 * @tc.desc: Test Session CloseChannel.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, CloseChannelA_Test003, TestSize.Level1)
{
    std::string name = "eSE";
    bool connected = true;
    uint8_t channelNum = 101;
    bool isBasicChannel = false;
    std::string callingUniqueTag;
    std::shared_ptr<SecureElementAgent> agent = std::make_shared<SecureElementAgent>(name);
    agent->Initialize();
    agent->OnStateChange(connected);
    agent->CloseChannel(channelNum, isBasicChannel, callingUniqueTag);
    EXPECT_TRUE(agent != nullptr);
}

/**
 * @tc.name: CloseChannelA_Test004
 * @tc.desc: Test Session CloseChannel.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, CloseChannelA_Test004, TestSize.Level1)
{
    std::string name = "eSE";
    bool connected = true;
    uint8_t channelNum = 101;
    bool isBasicChannel = true;
    std::string callingUniqueTag;
    std::shared_ptr<SecureElementAgent> agent = std::make_shared<SecureElementAgent>(name);
    agent->OnStateChange(connected);
    agent->CloseChannel(channelNum, isBasicChannel, callingUniqueTag);
    EXPECT_TRUE(agent != nullptr);
}

/**
 * @tc.name: CloseChannelA_Test005
 * @tc.desc: Test Session CloseChannel.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, CloseChannelA_Test005, TestSize.Level1)
{
    std::string name = "eSE";
    bool connected = true;
    uint8_t channelNum = 0;
    bool isBasicChannel = false;
    std::string callingUniqueTag;
    std::shared_ptr<SecureElementAgent> agent = std::make_shared<SecureElementAgent>(name);
    agent->OnStateChange(connected);
    agent->CloseChannel(channelNum, isBasicChannel, callingUniqueTag);
    EXPECT_TRUE(agent != nullptr);
}

/**
 * @tc.name: CloseChannelA_Test006
 * @tc.desc: Test Session CloseChannel.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, CloseChannelA_Test006, TestSize.Level1)
{
    std::string name = "SIM";
    bool connected = true;
    uint8_t channelNum = 101;
    bool isBasicChannel = false;
    std::string callingUniqueTag;
    std::shared_ptr<SecureElementAgent> agent = std::make_shared<SecureElementAgent>(name);
    agent->OnStateChange(connected);
    agent->CloseChannel(channelNum, isBasicChannel, callingUniqueTag);
    EXPECT_TRUE(agent != nullptr);
}

/**
 * @tc.name: CloseChannelA_Test007
 * @tc.desc: Test Session CloseChannel.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, CloseChannelA_Test007, TestSize.Level1)
{
    std::string name = "SIM";
    bool connected = true;
    uint8_t channelNum = 101;
    bool isBasicChannel = false;
    std::string callingUniqueTag;
    std::shared_ptr<SecureElementAgent> agent = std::make_shared<SecureElementAgent>(name);
    agent->Initialize();
    agent->OnStateChange(connected);
    agent->CloseChannel(channelNum, isBasicChannel, callingUniqueTag);
    EXPECT_TRUE(agent != nullptr);
}

/**
 * @tc.name: ResetA_Test001
 * @tc.desc: Test Session Reset.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, ResetA_Test001, TestSize.Level1)
{
    std::string name = "eSE";
    bool connected = false;
    std::shared_ptr<SecureElementAgent> agent = std::make_shared<SecureElementAgent>(name);
    agent->OnStateChange(connected);
    bool ret = agent->Reset();
    EXPECT_TRUE(!ret);
}

/**
 * @tc.name: ResetA_Test002
 * @tc.desc: Test Session Reset.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, ResetA_Test002, TestSize.Level1)
{
    std::string name = "eSE";
    bool connected = true;
    std::shared_ptr<SecureElementAgent> agent = std::make_shared<SecureElementAgent>(name);
    agent->OnStateChange(connected);
    bool ret = agent->Reset();
    EXPECT_TRUE(!ret);
}

/**
 * @tc.name: ResetA_Test003
 * @tc.desc: Test Session Reset.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, ResetA_Test003, TestSize.Level1)
{
    std::string name = "eSE";
    bool connected = true;
    std::shared_ptr<SecureElementAgent> agent = std::make_shared<SecureElementAgent>(name);
    agent->Initialize();
    agent->OnStateChange(connected);
    bool ret = agent->Reset();
    EXPECT_TRUE(ret);
}

/**
 * @tc.name: ResetA_Test004
 * @tc.desc: Test Session Reset.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, ResetA_Test004, TestSize.Level1)
{
    std::string name = "SIM";
    bool connected = true;
    std::shared_ptr<SecureElementAgent> agent = std::make_shared<SecureElementAgent>(name);
    agent->OnStateChange(connected);
    bool ret = agent->Reset();
    EXPECT_TRUE(!ret);
}

/**
 * @tc.name: ResetA_Test005
 * @tc.desc: Test Session Reset.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, ResetA_Test005, TestSize.Level1)
{
    std::string name = "SIM";
    bool connected = true;
    std::shared_ptr<SecureElementAgent> agent = std::make_shared<SecureElementAgent>(name);
    agent->Initialize();
    agent->OnStateChange(connected);
    bool ret = agent->Reset();
    EXPECT_TRUE(ret);
}

/**
 * @tc.name: OpenBasicChannelWithoutChannelAccess_Test001
 * @tc.desc: Test Session OpenBasicChannelWithoutChannelAccess.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, OpenBasicChannelWithoutChannelAccess_Test001, TestSize.Level1)
{
    std::string name = "eSE";
    bool connected = true;
    std::string aid = "a00000015100000";
    uint8_t p2 = 0;
    std::string response = "";
    std::shared_ptr<SecureElementAgent> agent = std::make_shared<SecureElementAgent>(name);
    agent->Initialize();
    agent->OnStateChange(connected);
    agent->OpenBasicChannelWithoutChannelAccess(aid, p2, response);
    EXPECT_TRUE(agent != nullptr);
}

/**
 * @tc.name: OpenBasicChannelWithoutChannelAccess_Test002
 * @tc.desc: Test Session OpenBasicChannelWithoutChannelAccess.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, OpenBasicChannelWithoutChannelAccess_Test002, TestSize.Level1)
{
    std::string name = "SIM";
    bool connected = true;
    std::string aid = "a00000015100000";
    uint8_t p2 = 0;
    std::string response = "";
    std::shared_ptr<SecureElementAgent> agent = std::make_shared<SecureElementAgent>(name);
    agent->Initialize();
    agent->OnStateChange(connected);
    agent->OpenBasicChannelWithoutChannelAccess(aid, p2, response);
    EXPECT_TRUE(agent != nullptr);
}

/**
 * @tc.name: OpenBasicChannel_Test001
 * @tc.desc: Test Session OpenBasicChannel.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, OpenBasicChannel_Test001, TestSize.Level1)
{
    std::string name = "eSE";
    bool connected = true;
    std::string aid = "a00000015100000";
    uint8_t p2 = 0;
    std::string response = "";
    std::shared_ptr<SecureElementAgent> agent = std::make_shared<SecureElementAgent>(name);
    agent->Initialize();
    agent->OnStateChange(connected);
    agent->OpenBasicChannel(aid, p2, response);
    EXPECT_TRUE(agent != nullptr);
}

/**
 * @tc.name: OpenBasicChannel_Test002
 * @tc.desc: Test Session OpenBasicChannel.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, OpenBasicChannel_Test002, TestSize.Level1)
{
    std::string name = "SIM";
    bool connected = true;
    std::string aid = "a00000015100000";
    uint8_t p2 = 0;
    std::string response = "";
    std::shared_ptr<SecureElementAgent> agent = std::make_shared<SecureElementAgent>(name);
    agent->Initialize();
    agent->OnStateChange(connected);
    agent->OpenBasicChannel(aid, p2, response);
    EXPECT_TRUE(agent != nullptr);
}

/**
 * @tc.name: OpenLogicalChannel_Test001
 * @tc.desc: Test Session OpenLogicalChannel.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, OpenLogicalChannel_Test001, TestSize.Level1)
{
    std::string name = "eSE";
    bool connected = true;
    std::string aid = "a00000015100000";
    uint8_t p2 = 0;
    std::string response = "";
    std::shared_ptr<SecureElementAgent> agent = std::make_shared<SecureElementAgent>(name);
    agent->Initialize();
    agent->OnStateChange(connected);
    agent->OpenLogicalChannel(aid, p2, response);
    EXPECT_TRUE(agent != nullptr);
}

/**
 * @tc.name: OpenLogicalChannel_Test002
 * @tc.desc: Test Session OpenLogicalChannel.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, OpenLogicalChannel_Test002, TestSize.Level1)
{
    std::string name = "SIM";
    bool connected = true;
    std::string aid = "a00000015100000";
    uint8_t p2 = 0;
    std::string response = "";
    std::shared_ptr<SecureElementAgent> agent = std::make_shared<SecureElementAgent>(name);
    agent->Initialize();
    agent->OnStateChange(connected);
    agent->OpenLogicalChannel(aid, p2, response);
    EXPECT_TRUE(agent != nullptr);
}

/**
 * @tc.name: OpenLogicalChannelWithoutChannelAccess_Test001
 * @tc.desc: Test Session OpenLogicalChannelWithoutChannelAccess.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, OpenLogicalChannelWithoutChannelAccess_Test001, TestSize.Level1)
{
    std::string name = "eSE";
    bool connected = true;
    std::string aid = "a00000015100000";
    uint8_t p2 = 0;
    std::string response = "";
    std::shared_ptr<SecureElementAgent> agent = std::make_shared<SecureElementAgent>(name);
    agent->Initialize();
    agent->OnStateChange(connected);
    agent->OpenLogicalChannelWithoutChannelAccess(aid, p2, response);
    EXPECT_TRUE(agent != nullptr);
}

/**
 * @tc.name: OpenLogicalChannelWithoutChannelAccess_Test002
 * @tc.desc: Test Session OpenLogicalChannelWithoutChannelAccess.
 * @tc.type: FUNC
 */
HWTEST_F(ChannelImplTest, OpenLogicalChannelWithoutChannelAccess_Test002, TestSize.Level1)
{
    std::string name = "SIM";
    bool connected = true;
    std::string aid = "a00000015100000";
    uint8_t p2 = 0;
    std::string response = "";
    std::shared_ptr<SecureElementAgent> agent = std::make_shared<SecureElementAgent>(name);
    agent->Initialize();
    agent->OnStateChange(connected);
    agent->OpenLogicalChannelWithoutChannelAccess(aid, p2, response);
    EXPECT_TRUE(agent != nullptr);
}
} // TEST
} // SE
} // OHOS